<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id = 'a'>
        一次不死，并且{{message}}，懂的都懂
    </div>
    <script>
        // 一、初次渲染数据内容
        var data = {
            message: "超神"
        }
        // 1.用正则表达式查找{{}}包裹的字符
        var el = document.querySelector('#a')
        var str = el.innerHTML
        var reg = /\{\{([^{}]+)\}\}/
        if (reg.test(str)) {
            var $1 = RegExp.$1
            var message = data[$1]
            el.innerHTML = el.innerHTML.replace(reg, message)
        }

        // 2.当数据修改的时候二次渲染
        var val = data.message
        Object.defineProperty(data, "message", {
            get: function() {
                console.log('get...')
                return val
            },
            set: function(value) {
                console.log('set...')
                var old = val
                el.innerHTML = el.innerHTML.replace(old, value)
                if (val != value) {
                    val = value
                }
            },
            configurable: true,
            enumerable: true
        })
        
        


    </script>
</body>
</html>